// function findpassword(){
//     var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
//     var code = document.getElementById("code").value;
//     var account = document.getElementById("account").value;
//     var email = document.getElementById("email").value;
//     var newpassword = document.getElementById("newpassword").value;
//     var repassword = document.getElementById("repassword").value;
//     if(typeof(email)=="undefined"){
//         document.getElementById("floatContent").innerHTML = "<div>" + "邮箱不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else if(typeof(account)=="undefined"){
//         document.getElementById("floatContent").innerHTML = "<div>" + "用户名不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else if(typeof(newpassword)=="undefined"){
//         document.getElementById("floatContent").innerHTML = "<div>" + "新密码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else if(typeof(repassword)=="undefined"){
//         document.getElementById("floatContent").innerHTML = "<div>" + "旧密码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else if(typeof(code)=="undefined"){
//         document.getElementById("floatContent").innerHTML = "<div>" + "验证码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else if(!myreg.test(email)) {
//         document.getElementById("floatContent").innerHTML = "<div>" + "请输入有效的E_mail！" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else if(newpassword !=repassword){
//         document.getElementById("floatContent").innerHTML = "<div>" + "请保证两次密码一致" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     }else{
//         axios.post({
//             url:"",
//             data:{
//                 Code:code,
//                 account:account,
//                 email:email,
//                 newPassword:newpassword,
//                 reNewPassword:repassword
//             }
//             .then(function(data){
//                 if(data.code==0){
//                     document.getElementById("floatContent").innerHTML ="<div>"+ "恭喜您"+"</div>"+"<div>"+"修改密码成功"+"</div>"+"<button onclick='closethis();passwordlog()' class='newbtn'>"+"确定"+"</button>";
//                     document.getElementById("floatContent").classList.remove("hide");
//                 }else{
//                     document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+"</div>"+"<div>"+"修改密码失败"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
//                     document.getElementById("floatContent").classList.remove("hide");
//                 }
//             })
//             .catch(function (error){
//                 document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+"</div>"+"<div>"+"请检查网络情况"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
//                 document.getElementById("floatContent").classList.remove("hide");
//             })
//         })
//     }
// }
var  send = () => {
    document.getElementById("floatContent").innerHTML = `
    <div class="floatTop">请输入图片中的数字</div>
    <button id="close" onclick="click()"><i class="fa fa-times  fa-2x" aria-hidden="true"></i></button>
    <canvas id="canvas" onclick="dr()"></canvas>
    <input type="text" id="codetext" name="ps" class="inputFirst" placeholder="请输入验证码">
    <button id="yes" onclick="sublim() ; closethis()">确定</button>
    </div>`
    document.getElementById("floatContent").classList.remove("hide");
    document.getElementById("close").onclick = function () {
        closethis()        
    }
    draw(show_num);  
}
var show_num = [];
function dr(){
draw(show_num);   
}
function sublim(){
    var val=document.getElementById("codetext").value;  
    var num = show_num.join("");//把数组元素转换为字符串
    if(val==''){
        alert('请输入验证码！');
    }else if(val == num){
        alert('提交成功！');
        sendma();
    }else{
        alert('验证码错误！请重新输入！');
        document.getElementById("text").value='';
        draw(show_num);
    }
}
function draw(show_num) {
    var canvas_width=document.getElementById('canvas').clientWidth;
    var canvas_height=document.getElementById('canvas').clientHeight;
    var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
    var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
    canvas.width = canvas_width;
    canvas.height = canvas_height;
    var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m";
    var aCode = sCode.split(",");
    var aLength = aCode.length;//获取到数组的长度
        
    for (var i = 0; i <= 3; i++) {
        var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
        var deg = (Math.random() * 30 * Math.PI / 180); //产生0~30之间的随机弧度
        var txt = aCode[j];//得到随机的一个内容
        show_num[i] = txt;
        var x = 10 + i * 20;//文字在canvas上的x坐标 
        var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
        context.font = "bold 23px 微软雅黑";    //文字样式

        context.translate(x, y);
        context.rotate(deg);

        context.fillStyle = randomColor();
        context.fillText(txt, 0, 0);     //加入文本

        context.rotate(-deg);            //角度变换
        context.translate(-x, -y);       //位置变换
    }
    for (var i = 0; i <= 5; i++) { //验证码上显示线条 ，5条线
        context.strokeStyle = randomColor();
        context.beginPath();         //开始一条路径
        context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
        context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);   //创建从哪到哪的一条线
        context.stroke();          //绘制一条路径
    }
    for (var i = 0; i <= 30; i++) { //验证码上显示小点 ，30个点
        context.strokeStyle = randomColor();
        context.beginPath();         //开始一条路径
        var x = Math.random() * canvas_width;
        var y = Math.random() * canvas_height;
        context.moveTo(x, y);
        context.lineTo(x + 1, y + 1);//同样是线，但是因为长度为1，就变成了点
        context.stroke();           //绘制一条路径
    }
}
function randomColor() {//得到随机的颜色值
    var r = Math.floor(Math.random() * 256);
    var g = Math.floor(Math.random() * 256);
    var b = Math.floor(Math.random() * 256);
    return "rgb(" + r + "," + g + "," + b + ")";
}
function sendma(){
    var email = document.getElementById("email").value;
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if (!myreg.test(email)) {
        document.getElementById("floatContent").innerHTML = "<div>" + "提示\n请输入有效的E_mail！" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else{
        axios.post('/home/register/email/sendAuthCodeEmail',{
            params:{
                email: email,
            }
        }).then(function (data) {
            var totalTime = 60;
            if (data.data.data.code == 20000) {
                document.getElementById("send").style.backgroundColor='lightgray'
                document.getElementById("send").style.color='white'
                document.getElementById("noclick").style.display='block'
                let clock = window.setInterval(() =>{
                    totalTime--;
                    document.getElementById("send").innerHTML = totalTime+'s后重新发送'
                    if(totalTime == 0){
                        document.getElementById("send").style.backgroundColor='#F96C0C'
                        document.getElementById("send").style.color='white'
                        document.getElementById("noclick").style.display='none'
                        window.clearInterval(clock)
                        document.getElementById("send").innerHTML = '重新发送'
                        totalTime = 60;
                    }
                },1000)
                document.getElementById("floatContent").innerHTML = "<div>" + "验证码已发送" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
                document.getElementById("floatContent").classList.remove("hide");
            }else{
                document.getElementById("floatContent").innerHTML = "<div>" + "验证码发送失败" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
                document.getElementById("floatContent").classList.remove("hide");
            }
        }).catch(function (error) {
            console.log(error)
            document.getElementById("floatContent").innerHTML = "<div>" + "请检查网络状况" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
            document.getElementById("floatContent").classList.remove("hide");
        })
    };
}
function findpassword(){
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    var code=document.getElementById("code").value;
    var email=document.getElementById("email").value;
    var newPassword=document.getElementById("newpassword").value;
    var rePassword=document.getElementById("repassword").value;
    if(typeof(email)=="undefined" || email==``){
        document.getElementById("floatContent").innerHTML = "<div>" + "邮箱不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else if(typeof(account)=="undefined" || account==``){
        document.getElementById("floatContent").innerHTML = "<div>" + "用户名不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else if(typeof(newPassword)=="undefined" || newPassword==``){
        document.getElementById("floatContent").innerHTML = "<div>" + "新密码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else if(typeof(rePassword)=="undefined" || rePassword==``){
        document.getElementById("floatContent").innerHTML = "<div>" + "旧密码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else if(typeof(code)=="undefined" || code==``){
        document.getElementById("floatContent").innerHTML = "<div>" + "验证码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else if(!myreg.test(email)) {
        document.getElementById("floatContent").innerHTML = "<div>" + "请输入有效的E_mail！" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else if(newPassword !=rePassword){
        document.getElementById("floatContent").innerHTML = "<div>" + "请保证两次密码一致" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
        document.getElementById("floatContent").classList.remove("hide");
    }else{
        axios.put('/home/find/user/forgetPassword',{
            params:{    
                code:code,            
                email:email,
                newPassword:newPassword
            }
        })
        .then(function(data) {
            if (data.data.data.code == 20000) {
                var list = data.data;
                console.log(list)
                document.getElementById("floatContent").innerHTML = "<div>" + "恭喜您"  + "</div>" + "<div>" + "修改成功" + "</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
                document.getElementById("floatContent").classList.remove("hide");
                localStorage.setItem("serveornot",1)
                localStorage.setItem("servename",account)
                localStorage.setItem("servepassword",password)
            } else {
                document.getElementById("floatContent").innerHTML = "<div>" + "很抱歉" + "</div>" + "<div>" + "修改失败" + "</div>" + "<button  onclick='closethis()' class='newbtn'>" + "确定" + "</button> ";
                document.getElementById("floatContent").classList.remove("hide");
            }
        })
        .catch(function (error){
            console.log(error)
            document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+"</div>"+"<div>"+"请检查网络情况"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
            document.getElementById("floatContent").classList.remove("hide");
        })
    }
}
function  closethis(){
    document.getElementById("floatContent").classList.add("hide");
}